package com.dxf.bigdata.D05_spark_again

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Intersection_union_substrict_zip {

  def main(args: Array[String]): Unit = {

    val sparkConf = new SparkConf().setMaster("local[*]").setAppName("app")

    val sc = new SparkContext(sparkConf)


    val rdd1: RDD[Int] = sc.makeRDD(List(1, 2, 3, 4))
    val rdd2: RDD[Int] = sc.makeRDD(List(5, 6, 3, 4))
    val rdd3: RDD[String] = sc.makeRDD(List("1", "2", "3", "4"))


    val value1: RDD[Int] = rdd1.subtract(rdd2)//差集
    val value2: RDD[Int] = rdd1.intersection(rdd2)//交集
    val value3: RDD[Int] = rdd1.union(rdd2)//并集

    val value5: RDD[(Int, Int)] = rdd1.zip(rdd2) //拉链, 数据个数一样,分区个数一样

    val value4: RDD[Int] = rdd1.union(rdd2).subtract(rdd1.intersection(rdd2))
    val value6: RDD[(Int, String)] = rdd1.zip(rdd3)

    println(value1.collect().mkString(","))
    println(value2.collect().mkString(","))
    println(value3.collect().mkString(","))
    println(value4.collect().mkString(","))
    println(value5.collect().mkString(","))
    println(value6.collect().mkString(","))

    //别忘记
    sc.stop()


  }
}